<script lang="ts" setup>
import { computed, unref } from 'vue'
import FrameLayout from '@/layouts/iframe/index.vue'

import { useRootSetting } from '@/hooks/setting/useRootSetting'
import { useMultipleTabStore } from '@/store/modules/multipleTab'

defineOptions({ name: 'PageLayout' })

const tabStore = useMultipleTabStore()

const { getOpenKeepAlive, getCanEmbedIFramePage } = useRootSetting()

const openCache = computed(() => unref(getOpenKeepAlive))

const getCaches = computed((): string[] => {
  if (!unref(getOpenKeepAlive))
    return []

  return tabStore.getCachedTabList
})
</script>

<template>
  <RouterView>
    <template #default="{ Component, route }">
      <transition
        name="fade-slide"
        mode="out-in"
        appear
      >
        <keep-alive v-if="openCache" :include="getCaches">
          <component :is="Component" :key="route.fullPath" />
        </keep-alive>
        <component :is="Component" v-else :key="route.fullPath" />
      </transition>
    </template>
  </RouterView>
  <FrameLayout v-if="getCanEmbedIFramePage" />
</template>
